<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <base href="<%=request.getContextPath()%>/">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>新增科室</title>
  <link rel="stylesheet" href="statics/css/hisStyle.css">
  <link rel="stylesheet" href="statics/css/common-styles.css">
</head>
<body>
<%@include file="../common/sidebar.jsp"%>
<div class="main-content">
  <%@include file="../common/top.jsp"%>
  <div class="content">
    <div class="function-page">
      <!-- 页面标题 -->
      <div class="page-header">
        <h1>新增科室</h1>
      </div>

      <!-- 错误提示 -->
      <c:if test="${not empty errorMessage}">
        <div class="message error-message">
            ${errorMessage}
        </div>
      </c:if>

      <div class="card">
        <h2 class="section-title">新增科室</h2>
        <form action="department/add" method="post">
        <div class="form-group">
          <label for="hospitalid">所属医院：</label>
          <select id="hospitalid" name="hospitalid" class="form-control" required>
            <option value="">-- 请选择医院 --</option>
            <c:forEach items="${hospitalList}" var="hospital">
              <option value="${hospital.hospitalId}">
                  ${hospital.hospitalName}
              </option>
            </c:forEach>
          </select>
        </div>
        <div class="form-group">
          <label for="deptname">科室名称：</label>
          <select id="deptname" name="deptname" class="form-control" required>
            <option value="">-- 请选择科室 --</option>
            <option value="内科" ${sessionScope.addDepartment.deptname == '内科' ? 'selected' : ''}>内科</option>
            <option value="心内科" ${sessionScope.addDepartment.deptname == '心内科' ? 'selected' : ''}>心内科</option>
            <option value="消化内科" ${sessionScope.addDepartment.deptname == '消化内科' ? 'selected' : ''}>消化内科</option>
            <option value="呼吸内科" ${sessionScope.addDepartment.deptname == '呼吸内科' ? 'selected' : ''}>呼吸内科</option>
            <option value="神经内科" ${sessionScope.addDepartment.deptname == '神经内科' ? 'selected' : ''}>神经内科</option>
            <option value="内分泌科" ${sessionScope.addDepartment.deptname == '内分泌科' ? 'selected' : ''}>内分泌科</option>
            <option value="肾内科" ${sessionScope.addDepartment.deptname == '肾内科' ? 'selected' : ''}>肾内科</option>
            <option value="血液内科" ${sessionScope.addDepartment.deptname == '血液内科' ? 'selected' : ''}>血液内科</option>
            <option value="风湿免疫科" ${sessionScope.addDepartment.deptname == '风湿免疫科' ? 'selected' : ''}>风湿免疫科</option>
            <option value="感染科" ${sessionScope.addDepartment.deptname == '感染科' ? 'selected' : ''}>感染科</option>
            <option value="外科" ${sessionScope.addDepartment.deptname == '外科' ? 'selected' : ''}>外科</option>
            <option value="普通外科" ${sessionScope.addDepartment.deptname == '普通外科' ? 'selected' : ''}>普通外科</option>
            <option value="肝胆外科" ${sessionScope.addDepartment.deptname == '肝胆外科' ? 'selected' : ''}>肝胆外科</option>
            <option value="神经外科" ${sessionScope.addDepartment.deptname == '神经外科' ? 'selected' : ''}>神经外科</option>
            <option value="胸外科" ${sessionScope.addDepartment.deptname == '胸外科' ? 'selected' : ''}>胸外科</option>
            <option value="心外科" ${sessionScope.addDepartment.deptname == '心外科' ? 'selected' : ''}>心外科</option>
            <option value="泌尿外科" ${sessionScope.addDepartment.deptname == '泌尿外科' ? 'selected' : ''}>泌尿外科</option>
            <option value="骨科" ${sessionScope.addDepartment.deptname == '骨科' ? 'selected' : ''}>骨科</option>
            <option value="整形外科" ${sessionScope.addDepartment.deptname == '整形外科' ? 'selected' : ''}>整形外科</option>
            <option value="烧伤科" ${sessionScope.addDepartment.deptname == '烧伤科' ? 'selected' : ''}>烧伤科</option>
            <option value="妇产科" ${sessionScope.addDepartment.deptname == '妇产科' ? 'selected' : ''}>妇产科</option>
            <option value="产科" ${sessionScope.addDepartment.deptname == '产科' ? 'selected' : ''}>产科</option>
            <option value="妇科" ${sessionScope.addDepartment.deptname == '妇科' ? 'selected' : ''}>妇科</option>
            <option value="儿科" ${sessionScope.addDepartment.deptname == '儿科' ? 'selected' : ''}>儿科</option>
            <option value="新生儿科" ${sessionScope.addDepartment.deptname == '新生儿科' ? 'selected' : ''}>新生儿科</option>
            <option value="眼科" ${sessionScope.addDepartment.deptname == '眼科' ? 'selected' : ''}>眼科</option>
            <option value="耳鼻喉科" ${sessionScope.addDepartment.deptname == '耳鼻喉科' ? 'selected' : ''}>耳鼻喉科</option>
            <option value="口腔科" ${sessionScope.addDepartment.deptname == '口腔科' ? 'selected' : ''}>口腔科</option>
            <option value="皮肤科" ${sessionScope.addDepartment.deptname == '皮肤科' ? 'selected' : ''}>皮肤科</option>
            <option value="精神心理科" ${sessionScope.addDepartment.deptname == '精神心理科' ? 'selected' : ''}>精神心理科</option>
            <option value="中医科" ${sessionScope.addDepartment.deptname == '中医科' ? 'selected' : ''}>中医科</option>
            <option value="中医内科" ${sessionScope.addDepartment.deptname == '中医内科' ? 'selected' : ''}>中医内科</option>
            <option value="中医外科" ${sessionScope.addDepartment.deptname == '中医外科' ? 'selected' : ''}>中医外科</option>
            <option value="针灸推拿科" ${sessionScope.addDepartment.deptname == '针灸推拿科' ? 'selected' : ''}>针灸推拿科</option>
            <option value="康复医学科" ${sessionScope.addDepartment.deptname == '康复医学科' ? 'selected' : ''}>康复医学科</option>
            <option value="麻醉科" ${sessionScope.addDepartment.deptname == '麻醉科' ? 'selected' : ''}>麻醉科</option>
            <option value="急诊科" ${sessionScope.addDepartment.deptname == '急诊科' ? 'selected' : ''}>急诊科</option>
            <option value="重症医学科" ${sessionScope.addDepartment.deptname == '重症医学科' ? 'selected' : ''}>重症医学科</option>
            <option value="病理科" ${sessionScope.addDepartment.deptname == '病理科' ? 'selected' : ''}>病理科</option>
            <option value="检验科" ${sessionScope.addDepartment.deptname == '检验科' ? 'selected' : ''}>检验科</option>
            <option value="医学影像科" ${sessionScope.addDepartment.deptname == '医学影像科' ? 'selected' : ''}>医学影像科</option>
            <option value="超声科" ${sessionScope.addDepartment.deptname == '超声科' ? 'selected' : ''}>超声科</option>
            <option value="核医学科" ${sessionScope.addDepartment.deptname == '核医学科' ? 'selected' : ''}>核医学科</option>
            <option value="药剂科" ${sessionScope.addDepartment.deptname == '药剂科' ? 'selected' : ''}>药剂科</option>
            <option value="预防保健科" ${sessionScope.addDepartment.deptname == '预防保健科' ? 'selected' : ''}>预防保健科</option>
            <option value="营养科" ${sessionScope.addDepartment.deptname == '营养科' ? 'selected' : ''}>营养科</option>
          </select>
        </div>
        <div class="form-group">
          <label for="illness">诊疗范围：</label>
          <textarea id="illness" name="illness" class="form-control" rows="3">${sessionScope.addDepartment.illness}</textarea>
        </div>
        <div class="form-group">
          <label for="equipment">设备配置：</label>
          <textarea id="equipment" name="equipment" class="form-control" rows="3">${sessionScope.addDepartment.equipment}</textarea>
        </div>
        <div class="form-actions">
          <button type="button" class="btn btn-secondary" onclick="window.location.href='department/find'">返回列表</button>
          <button type="submit" class="btn btn-primary">保存</button>
        </div>
      </form>
      </div>
    </div>
  </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 表单验证
        const form = document.querySelector('form');
        form.addEventListener('submit', function(event) {
            const deptname = document.getElementById('deptname').value;
            const hospitalid = document.getElementById('hospitalid').value;
            
            let isValid = true;
            let errorMsg = '';
            
            if (!deptname) {
                isValid = false;
                errorMsg = '科室名称不能为空';
            } else if (!hospitalid) {
                isValid = false;
                errorMsg = '请选择所属医院';
            }
            
            if (!isValid) {
                alert(errorMsg);
                event.preventDefault();
            }
        });
    });
</script>

</body>
</html>